/**
 * Created by mantoo on 2018/4/9.
 */


var myChart = echarts.init(document.getElementById('intoChart'));
var option = {
    title : {
        text: '用户自己生成的图表',
        subtext: 'support by Echart'
    },
    tooltip : {
        trigger: 'axis'
    },
    legend: {
        data:[]
    },
    toolbox: {
        show : true,
        feature : {
            dataView : {show: true, readOnly: false},
            magicType : {show: true, type: ['line', 'bar']},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    calculable : true,
    xAxis : [
        {
            type : 'category',
            data : []
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : [
        {
            name:'',
            type:'bar',
            data:[],
            markPoint : {
                data : [
                    {type : 'max', name: '最大值'},
                    {type : 'min', name: '最小值'}
                ]
            },
            markLine : {
                data : [
                    {type : 'average', name: '平均值'}
                ]
            }
        },
        {
            name:'',
            type:'bar',
            data:[],
            markPoint : {
                data : [
                    {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183},
                    {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
                ]
            },
            markLine : {
                data : [
                    {type : 'average', name : '平均值'}
                ]
            }
        },{
            name:'',
            type:'bar',
            data:[],
            markPoint : {
                data : [
                    {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183},
                    {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
                ]
            },
            markLine : {
                data : [
                    {type : 'average', name : '平均值'}
                ]
            }
        },{
            name:'',
            type:'bar',
            data:[],
            markPoint : {
                data : [
                    {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183},
                    {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
                ]
            },
            markLine : {
                data : [
                    {type : 'average', name : '平均值'}
                ]
            }
        }
    ]
};

function intoChart(thisDict){
console.log(thisDict);
          option.legend.data[0]=thisDict['legend'];
          for (i=0;i<thisDict['rowCol'][0];i++){
            option.series[i].data = thisDict[String(thisDict['legend'][i])];
            option.series[i].name = String(thisDict['legend'][i])
          }
          option.xAxis[0].data = thisDict['xAxis'];
          // option.legend.data[0]=["吧"];
          // option.series[0].data = [1,3,4];
          // option.xAxis[0].data = ["啊","啊","地方","啊"];
          // option.legend.data[0]=['蒸发量','降水量'];
          // option.series[0].data = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3];
          // option.xAxis[0].data = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'];

    myChart.setOption(option);
}


